package org.truenewx.tnxjee.repo.mybatis.mapper;

import java.io.Serializable;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.truenewx.tnxjee.model.entity.unity.Unity;

public interface UnityMapper<T extends Unity<K>, K extends Serializable> extends EntityMapper<T> {

    @Override
    default int save(T unity) {
        if (unity.getId() == null) {
            return insert(unity);
        } else {
            return updateById(unity);
        }
    }

    default boolean existsById(K id) {
        return exists(new QueryWrapper<T>().eq(getIdColumnName(), id));
    }

    default String getIdColumnName() {
        return "id";
    }

}
